<template>
    <div>
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="user.username" name="username" label="用户名" placeholder="用户名"
                    :rules="[{ required: true, message: '请填写账号' }]" />
                <van-field v-model="user.password" type="password" name="password" label="密码" placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]" />
            </van-cell-group>
            <van-field  v-model="user.code" center clearable label="短信验证码" name="code" placeholder="请输入短信验证码" :rules="[{ required: true, message: '请填验证码' }]">
                <template #button>
                    <van-button size="small" type="primary" @click="yzm">{{zz}}</van-button>
                </template>
            </van-field>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    登录
                </van-button>
            </div>
        </van-form>
    </div>
</template>

<script setup>

import { ref } from 'vue';
import { usedl } from '../api/api';
import { setActivePinia } from 'pinia';
import { useRouter } from 'vue-router';
const router=useRouter()
const { user } = setActivePinia(usedl())
console.log(user);

const onSubmit = ({username,password,code}) => {
    
        if(username==='admin11'&&password==='1234567'&&code==='1234'&&password.length>6&&username.length>6)
        {
            alert('登录成功')
            router.push('/')
            localStorage.setItem('token','ssdsdsdsdfgg')
        }
        else
        {
            alert('登录失败')
        }
};

// const time=ref(5)
// const timer=null;
const zz=ref('发送验证码')
// const yzm=()=>{
//     timer.setInterval(() => {
//         if(time===1){
//             clearInterval(timer)
//             zz.value='发送验证码'
//         }
//         else
//         {
//             zz.value=`请在${time-1}秒后发送验证码`
//         }
//     }, 1000)
// }

</script>

<style></style>